package com.xdf.whiteaccount.controller;

import com.xdf.whiteaccount.dto.CpBillfh8Shelves;
import com.xdf.whiteaccount.dto.CpBillfhMainDTO;
import com.xdf.whiteaccount.entity.CpBillfh;
import com.xdf.whiteaccount.entity.CpBillfhMain;
import com.xdf.whiteaccount.entity.ResponseResult;
import com.xdf.whiteaccount.enums.ResponseEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

import com.xdf.whiteaccount.service.CpBillfhMainService;
import com.xdf.whiteaccount.utils.JsonResult;

/**
 * 版本号：20240401
 * 注意要有依赖：
 *         <dependency>
 *             <groupId>io.springfox</groupId>
 *             <artifactId>springfox-swagger2</artifactId>
 *             <version>2.9.2</version>
 *         </dependency>
 *         <dependency>
 *             <groupId>io.springfox</groupId>
 *             <artifactId>springfox-swagger-ui</artifactId>
 *             <version>2.9.2</version>
 *         </dependency>
 * 同时入口类头上使用注解：@EnableSwagger2
 * @Description : 控制层，自定义代码写在最后
 * @Author : chanchaw
 * @Date : 2025-4-14 11:00:43
 */
@Api(tags = "色布发货单")
@CrossOrigin
@RestController
@RequestMapping("/cpBillfhMain")
public class CpBillfhMainController {
    @Autowired
    private CpBillfhMainService service;

    // 全部属性新增
    @ApiOperation(value = "完全新增", httpMethod = "POST", notes = "推荐使用save请求")
    @PostMapping("/insert")
    public JsonResult insert(@RequestBody CpBillfhMain record){
        return JsonResult.ok(service.insert(record));
    }

    // 选择属性新增。value=null 的属性不会写入DB，DB会填充默认值
    @ApiOperation(value = "选择性新增", httpMethod = "POST", notes = "推荐使用save请求")
    @PostMapping("/insertSelective")
    public JsonResult insertSelective(@RequestBody CpBillfhMain record){
        return JsonResult.ok(service.insertSelective(record));
    }

    // 根据主键删除，切记表要有主键，否则为删除所有数据！！！！！！！！！！
    @ApiOperation(value = "根据主键删除", httpMethod = "POST", notes = "所有请求都是post")
    @PostMapping("/delete/{pk}")
    public JsonResult deleteByPrimaryKey(@PathVariable Integer pk){
        return JsonResult.ok(service.deleteByPrimaryKey(pk));
    }

    // 根据主键查询，切记表要有主键，否则为查询所有数据！！！！！！！！！！
    @ApiOperation(value = "根据主键查询", httpMethod = "POST", notes = "所有请求都是post")
    @PostMapping("/select/{pk}")
    public JsonResult selectByPrimaryKey(@PathVariable Integer pk){
        return JsonResult.ok(service.selectByPrimaryKey(pk));
    }

    // 获取所有数据
    @ApiOperation(value = "查询所有", httpMethod = "POST", notes = "所有请求都是post")
    @PostMapping("/selectAll")
    public JsonResult selectAll(){
        return JsonResult.ok(service.selectAll());
    }

    // 全部属性更新。前端传递来属性value=null则会设置后台数据为null
    @ApiOperation(value = "完全修改", httpMethod = "POST", notes = "推荐使用save方法")
    @PostMapping("/updateByPrimaryKey")
    public JsonResult updateByPrimaryKey(@RequestBody CpBillfhMain record) {
        return JsonResult.ok(service.updateByPrimaryKey(record));
    }

    // 部分属性更新。前端传递来value=null的属性不会被更新到数据库
    @ApiOperation(value = "选择性修改", httpMethod = "POST", notes = "推荐使用save方法")
    @PostMapping("/updateByPrimaryKeySelective")
    public JsonResult updateByPrimaryKeySelective(@RequestBody CpBillfhMain record) {
        return JsonResult.ok(service.updateByPrimaryKeySelective(record));
    }

    // 有则修改，无则新增。选择性保存，如果属性value=null则不会更新该字段
    @ApiOperation(value = "保存数据", httpMethod = "POST", notes = "主键为空则新增(选择性新增)，主键有值则修改（选择性修改）")
    @PostMapping("/save")
    public JsonResult save(@RequestBody CpBillfhMain record) {
        return JsonResult.ok(service.save(record));
    }

    // 是上面接口 save 的批量执行版本
    @ApiOperation(value = "对象数组保存", httpMethod = "POST", notes = "所有请求都是post")
    @PostMapping("/multiSave")
    public JsonResult multiSave(@RequestBody List<CpBillfhMain> records) {
        return JsonResult.ok(service.multiSave(records));
    }
    //=================以上是自动生成的代码，自定义代码请写在下面==================

    @ApiOperation(value = "erp端在细码单页面选择后生成发货单", httpMethod = "POST", notes = "erp端在细码单页面选择后生成发货单")
    @RequestMapping(value = "/insertToFH", method = RequestMethod.POST)
    public CpBillfhMain insertToFH(@RequestBody CpBillfhMainDTO cpBillfhMainDTO) throws Exception {
        return service.insertToFH(cpBillfhMainDTO.getFhd(), cpBillfhMainDTO.getList());
    }

    @ApiOperation(value = "erp端在细码单页面选择后生成发货单", httpMethod = "POST", notes = "erp端在细码单页面选择后生成发货单")
    @RequestMapping(value = "/deleteFhd/{id}", method = RequestMethod.POST)
    public JsonResult deleteFhd(@PathVariable("id") Integer id) throws Exception {
        return JsonResult.ok(service.deleteFhd(id));
    }

    /**
     * @Description : 修改
     * @Return : CpBillfh
     * @Author : 张柯
     * @Date : 2021-06-25 09:44:52
     */
    @ApiOperation(value = "修改", httpMethod = "POST", notes = "自动生成的修改方法")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResponseResult<Void> update(@RequestBody CpBillfhMain cpBillfhMain) throws Exception {
        service.update(cpBillfhMain);
        return ResponseResult.<Void>builder().success(true).message(ResponseEnum.OK.getName()).build();
    }
}